﻿Imports System.Text

Public Class Decoder
    Private M_AddrA As String
    Private M_AddrB As String
    Private m_Data As Byte()

    Public Property AddrA() As String
        Get
            Return M_AddrA
        End Get
        Set(ByVal value As String)
            M_AddrA = value
        End Set
    End Property
    Public Property AddrB() As String
        Get
            Return M_AddrB
        End Get
        Set(ByVal value As String)
            M_AddrB = value
        End Set
    End Property
    Public Function Decode(ByVal Bytes As Byte()) As Integer
        AddrA = Bytes(0).ToString
        AddrB = Bytes(1).ToString
        Dim C As Integer = CInt(Bytes(2))
        Dim Tmp(C - 1) As Byte
        Array.Copy(Bytes, 3, Tmp, 0, C)
        m_Data = Tmp
        Return C
    End Function
    Public Property Data() As Byte()
        Get
            Return m_Data
        End Get
        Set(ByVal value As Byte())
            m_Data = value
        End Set
    End Property
    Public Function DataToString() As String
        Return ConvertByteArrayToString(m_Data)
    End Function
    Private Function ConvertByteArrayToString(ByVal byteArray As Byte()) As String
        Dim enc As Encoding = Encoding.UTF8
        Dim text As String = enc.GetString(byteArray)
        Return text
    End Function
End Class
